//createRouter 创建路由实例
//createWebHistory 创建History模式路由
import {createRouter, createWebHistory} from 'vue-router'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    //配置path和component对应关系
    routes: [
        {
            path: '/',
            component: () => import('@/views/Layout/index.vue'),
            //二级路由配置，如果是一级路由页面里面切换就是二级路由
            children: [
                {
                    // path: '/home',
                    //将home页面置空，默认也会展示
                    path: '/',
                    component: () => import('@/views/Home/index.vue'),
                },
                {
                    path: '/category/:id',
                    component: () => import('@/views/Category/index.vue'),

                },
                {
                    //二级分类
                    path: '/category/sub/:id',
                    component: () => import('@/views/SubCategory/index.vue'),
                },
                {
                    path: '/detail/:id',
                    component: () => import('@/views/Detail/index.vue'),
                },
                {
                    path: '/cartlist',
                    component: () => import('@/views/CartList/index.vue'),
                },
                {
                    path: '/checkout',
                    component: () => import('@/views/Checkout/index.vue'),
                },
                {
                    path: '/pay',
                    component: () => import('@/views/Pay/index.vue'),
                },
            ]
        },
        {
            path: '/login',
            component: () => import('@/views/Login/index.vue'),
        },
    ],
    scrollBehavior() {
        return {top: 0}
    }
})

export default router
